package com.xyd.servlet;

import com.xyd.entity.Cart;
import com.xyd.entity.Message;
import com.xyd.entity.User;
import com.xyd.service.CartService;
import com.xyd.service.impl.CartServiceImpl;
import com.xyd.util.JsonUtil;
import java.io.IOException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 类描述：
 *
 * @author 张吉哲
 * @date 2021/1/13 9:14
 */
@WebServlet("/cartShowServlet")
public class CartShowServlet extends HttpServlet {

  @Override
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    User user = (User) request.getSession().getAttribute("user");
    Message message = new Message();
    if (user == null) {
      message.setFlag(false);
      message.setMessage("您尚未登陆，请登陆后再试");
      JsonUtil.toJson(response, message);
      return;
    }
    CartService cartService = new CartServiceImpl();
    List<Cart> carts = cartService.findAllMyCart(user.getEuUserId());

    JsonUtil.toJson(response,carts);
  }

  @Override
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    doPost(request, response);
  }
}
